/**
 * @Author 天下无敌
 * @Date 
 * @AIDE AIDE+ 
 */package com.ecs.core.screen.ui;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class CustomJoystick extends Touchpad {

    public CustomJoystick(float deadzoneRadius, float stickRadius) {
        super(deadzoneRadius, createTouchpadStyle(stickRadius));
    }

    private static TouchpadStyle createTouchpadStyle(float stickRadius) {
        Pixmap bgPixmap = new Pixmap((int)(stickRadius * 2.5f), (int)(stickRadius * 2.5f), Pixmap.Format.RGBA8888);
        bgPixmap.setColor(new Color(0.5f, 0.5f, 0.5f, 0.4f)); // 灰色半透明
        bgPixmap.fillCircle(bgPixmap.getWidth() / 2, bgPixmap.getHeight() / 2, (int)(stickRadius * 1.2f));

        Pixmap knobPixmap = new Pixmap((int)(stickRadius * 2), (int)(stickRadius * 2), Pixmap.Format.RGBA8888);
        knobPixmap.setColor(Color.WHITE);
        knobPixmap.fillCircle(knobPixmap.getWidth() / 2, knobPixmap.getHeight() / 2, (int)stickRadius);

        TextureRegionDrawable bgDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(bgPixmap)));
        TextureRegionDrawable knobDrawable = new TextureRegionDrawable(new TextureRegion(new Texture(knobPixmap)));

        bgPixmap.dispose();
        knobPixmap.dispose();

        TouchpadStyle style = new TouchpadStyle();
        style.background = bgDrawable;
        style.knob = knobDrawable;
        return style;
    }
}
